
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>3-14 构建离线应用 · 深入浅出 Webpack</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="吴浩麟">
        <meta name="identifier" content="9787121331725" scheme="ISBN">
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-modal/index.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        

    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="3-15搭配NpmScript.html" />
    
    
    <link rel="prev" href="3-13构建Npm模块.html" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"gwuhaolin","type":"follow","size":"small","width":"150"},{"user":"gwuhaolin","repo":"dive-into-webpack","type":"star","size":"small"}]};
    </script>


    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
  
  

  

  
  
  

<li class="chapter " data-level="1.1" data-path="../">
  
  <a href="../">
    
                    
                    深入浅出 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.2" data-path="../前言.html">
  
  <a href="../前言.html">
    
                    
                    前言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3" data-path="../1入门/">
  
  <a href="../1入门/">
    
                    
                    第1章 入门
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.3.1" data-path="../1入门/1-1前端的发展.html">
  
  <a href="../1入门/1-1前端的发展.html">
    
                    
                    1-1 前端的发展
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.2" data-path="../1入门/1-2常见的构建工具及对比.html">
  
  <a href="../1入门/1-2常见的构建工具及对比.html">
    
                    
                    1-2 常见的构建工具及对比
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.3" data-path="../1入门/1-3安装与使用.html">
  
  <a href="../1入门/1-3安装与使用.html">
    
                    
                    1-3 安装与使用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.4" data-path="../1入门/1-4使用Loader.html">
  
  <a href="../1入门/1-4使用Loader.html">
    
                    
                    1-4 使用 Loader
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.5" data-path="../1入门/1-5使用Plugin.html">
  
  <a href="../1入门/1-5使用Plugin.html">
    
                    
                    1-5 使用 Plugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.6" data-path="../1入门/1-6使用DevServer.html">
  
  <a href="../1入门/1-6使用DevServer.html">
    
                    
                    1-6 使用 DevServer
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.7" data-path="../1入门/1-7核心概念.html">
  
  <a href="../1入门/1-7核心概念.html">
    
                    
                    1-7 核心概念
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.4" data-path="../2配置/">
  
  <a href="../2配置/">
    
                    
                    第2章 配置
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.4.1" data-path="../2配置/2-1Entry.html">
  
  <a href="../2配置/2-1Entry.html">
    
                    
                    2-1 Entry
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.2" data-path="../2配置/2-2Output.html">
  
  <a href="../2配置/2-2Output.html">
    
                    
                    2-2 Output
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.3" data-path="../2配置/2-3Module.html">
  
  <a href="../2配置/2-3Module.html">
    
                    
                    2-3 Module
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.4" data-path="../2配置/2-4Resolve.html">
  
  <a href="../2配置/2-4Resolve.html">
    
                    
                    2-4 Resolve
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.5" data-path="../2配置/2-5Plugins.html">
  
  <a href="../2配置/2-5Plugins.html">
    
                    
                    2-5 Plugins
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.6" data-path="../2配置/2-6DevServer.html">
  
  <a href="../2配置/2-6DevServer.html">
    
                    
                    2-6 DevServer
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.7" data-path="../2配置/2-7其它配置项.html">
  
  <a href="../2配置/2-7其它配置项.html">
    
                    
                    2-7 其它配置项
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.8" data-path="../2配置/2-8整体配置结构.html">
  
  <a href="../2配置/2-8整体配置结构.html">
    
                    
                    2-8 整体配置结构
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.9" data-path="../2配置/2-9多种配置类型.html">
  
  <a href="../2配置/2-9多种配置类型.html">
    
                    
                    2-9 多种配置类型
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.10" data-path="../2配置/2-10配置总结.html">
  
  <a href="../2配置/2-10配置总结.html">
    
                    
                    2-10 配置总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.5" data-path="./">
  
  <a href="./">
    
                    
                    第3章 实战
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.5.1" data-path="3-1使用ES6语言.html">
  
  <a href="3-1使用ES6语言.html">
    
                    
                    3-1 使用 ES6 语言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.2" data-path="3-2使用TypeScript语言.html">
  
  <a href="3-2使用TypeScript语言.html">
    
                    
                    3-2 使用 TypeScript 语言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.3" data-path="3-3使用Flow检查器.html">
  
  <a href="3-3使用Flow检查器.html">
    
                    
                    3-3 使用 Flow 检查器
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.4" data-path="3-4使用SCSS语言.html">
  
  <a href="3-4使用SCSS语言.html">
    
                    
                    3-4 使用 SCSS
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.5" data-path="3-5使用PostCSS.html">
  
  <a href="3-5使用PostCSS.html">
    
                    
                    3-5 使用 PostCSS
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.6" data-path="3-6使用React框架.html">
  
  <a href="3-6使用React框架.html">
    
                    
                    3-6 使用 React 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.7" data-path="3-7使用Vue框架.html">
  
  <a href="3-7使用Vue框架.html">
    
                    
                    3-7 使用 Vue 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.8" data-path="3-8使用Angular2框架.html">
  
  <a href="3-8使用Angular2框架.html">
    
                    
                    3-8 使用 Angular2 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.9" data-path="3-9为单页应用生成HTML.html">
  
  <a href="3-9为单页应用生成HTML.html">
    
                    
                    3-9 为单页应用生成 HTML
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.10" data-path="3-10管理多个单页应用.html">
  
  <a href="3-10管理多个单页应用.html">
    
                    
                    3-10 管理多个单页应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.11" data-path="3-11构建同构应用.html">
  
  <a href="3-11构建同构应用.html">
    
                    
                    3-11 构建同构应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.12" data-path="3-12构建Electron应用.html">
  
  <a href="3-12构建Electron应用.html">
    
                    
                    3-12 构建 Electron 应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.13" data-path="3-13构建Npm模块.html">
  
  <a href="3-13构建Npm模块.html">
    
                    
                    3-13 构建 Npm 模块
            
    </a>
    

    
</li>

<li class="chapter active" data-level="1.5.14" data-path="3-14构建离线应用.html">
  
  <a href="3-14构建离线应用.html">
    
                    
                    3-14 构建离线应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.15" data-path="3-15搭配NpmScript.html">
  
  <a href="3-15搭配NpmScript.html">
    
                    
                    3-15 搭配 Npm Script
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.16" data-path="3-16检查代码.html">
  
  <a href="3-16检查代码.html">
    
                    
                    3-16 检查代码
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.17" data-path="3-17通过Node.jsAPI启动Webpack.html">
  
  <a href="3-17通过Node.jsAPI启动Webpack.html">
    
                    
                    3-17 通过 Node.js API 启动 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.18" data-path="3-18使用WebpackDevMiddleware.html">
  
  <a href="3-18使用WebpackDevMiddleware.html">
    
                    
                    3-18 使用 Webpack Dev Middleware
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.19" data-path="3-19加载图片.html">
  
  <a href="3-19加载图片.html">
    
                    
                    3-19 加载图片
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.20" data-path="3-20加载SVG.html">
  
  <a href="3-20加载SVG.html">
    
                    
                    3-20 加载SVG
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.21" data-path="3-21加载SourceMap.html">
  
  <a href="3-21加载SourceMap.html">
    
                    
                    3-21 加载 Source Map
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.22" data-path="3-22实战总结.html">
  
  <a href="3-22实战总结.html">
    
                    
                    3-22 实战总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.6" data-path="../4优化/">
  
  <a href="../4优化/">
    
                    
                    第4章 优化
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.6.1" data-path="../4优化/4-1缩小文件搜索范围.html">
  
  <a href="../4优化/4-1缩小文件搜索范围.html">
    
                    
                    4-1 缩小文件搜索范围
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.2" data-path="../4优化/4-2使用DllPlugin.html">
  
  <a href="../4优化/4-2使用DllPlugin.html">
    
                    
                    4-2 使用 DllPlugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.3" data-path="../4优化/4-3使用HappyPack.html">
  
  <a href="../4优化/4-3使用HappyPack.html">
    
                    
                    4-3 使用 HappyPack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.4" data-path="../4优化/4-4使用ParallelUglifyPlugin.html">
  
  <a href="../4优化/4-4使用ParallelUglifyPlugin.html">
    
                    
                    4-4 使用 ParallelUglifyPlugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.5" data-path="../4优化/4-5使用自动刷新.html">
  
  <a href="../4优化/4-5使用自动刷新.html">
    
                    
                    4-5 使用自动刷新
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.6" data-path="../4优化/4-6开启模块热替换.html">
  
  <a href="../4优化/4-6开启模块热替换.html">
    
                    
                    4-6 开启模块热替换
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.7" data-path="../4优化/4-7区分环境.html">
  
  <a href="../4优化/4-7区分环境.html">
    
                    
                    4-7 区分环境
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.8" data-path="../4优化/4-8压缩代码.html">
  
  <a href="../4优化/4-8压缩代码.html">
    
                    
                    4-8 压缩代码
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.9" data-path="../4优化/4-9CDN加速.html">
  
  <a href="../4优化/4-9CDN加速.html">
    
                    
                    4-9 CDN 加速
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.10" data-path="../4优化/4-10使用TreeShaking.html">
  
  <a href="../4优化/4-10使用TreeShaking.html">
    
                    
                    4-10 使用 Tree Shaking
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.11" data-path="../4优化/4-11提取公共代码.html">
  
  <a href="../4优化/4-11提取公共代码.html">
    
                    
                    4-11 提取公共代码
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.12" data-path="../4优化/4-12按需加载.html">
  
  <a href="../4优化/4-12按需加载.html">
    
                    
                    4-12 按需加载
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.13" data-path="../4优化/4-13使用Prepack.html">
  
  <a href="../4优化/4-13使用Prepack.html">
    
                    
                    4-13 使用 Prepack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.14" data-path="../4优化/4-14开启ScopeHoisting.html">
  
  <a href="../4优化/4-14开启ScopeHoisting.html">
    
                    
                    4-14 开启 Scope Hoisting
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.15" data-path="../4优化/4-15输出分析.html">
  
  <a href="../4优化/4-15输出分析.html">
    
                    
                    4-15 输出分析
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.16" data-path="../4优化/4-16优化总结.html">
  
  <a href="../4优化/4-16优化总结.html">
    
                    
                    4-16 优化总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.7" data-path="../5原理/">
  
  <a href="../5原理/">
    
                    
                    第5章 原理
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.7.1" data-path="../5原理/5-1工作原理概括.html">
  
  <a href="../5原理/5-1工作原理概括.html">
    
                    
                    5-1 工作原理概括
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.2" data-path="../5原理/5-2输出文件分析.html">
  
  <a href="../5原理/5-2输出文件分析.html">
    
                    
                    5-2 输出文件分析
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.3" data-path="../5原理/5-3编写Loader.html">
  
  <a href="../5原理/5-3编写Loader.html">
    
                    
                    5-3 编写 Loader
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.4" data-path="../5原理/5-4编写Plugin.html">
  
  <a href="../5原理/5-4编写Plugin.html">
    
                    
                    5-4 编写 Plugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.5" data-path="../5原理/5-5调试Webpack.html">
  
  <a href="../5原理/5-5调试Webpack.html">
    
                    
                    5-5 调试 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.6" data-path="../5原理/5-6原理总结.html">
  
  <a href="../5原理/5-6原理总结.html">
    
                    
                    5-6 原理总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.8" >
  
      <span>
            
                    
                    附录
            
    </span>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.8.1" data-path="../附录/常用Loaders.html">
  
  <a href="../附录/常用Loaders.html">
    
                    
                    常用 Loaders
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.8.2" data-path="../附录/常用Plugins.html">
  
  <a href="../附录/常用Plugins.html">
    
                    
                    常用 Plugins
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.8.3" data-path="../附录/其它Webpack学习资源.html">
  
  <a href="../附录/其它Webpack学习资源.html">
    
                    
                    其它 Webpack 学习资源
            
    </a>
    

    
</li>


    </ul>
    
</li>


  

  <li class="divider"></li>

  <li id="codefund_ad">
    <script src="https://codesponsor.io/scripts/5da524c5-301a-4ef4-8b42-696edd22e693/embed.js"></script>
  </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >3-14 构建离线应用</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="3-14-&#x6784;&#x5EFA;&#x79BB;&#x7EBF;&#x5E94;&#x7528;">3-14 &#x6784;&#x5EFA;&#x79BB;&#x7EBF;&#x5E94;&#x7528;</h1>
<h2 id="&#x8BA4;&#x8BC6;&#x79BB;&#x7EBF;&#x5E94;&#x7528;">&#x8BA4;&#x8BC6;&#x79BB;&#x7EBF;&#x5E94;&#x7528;</h2>
<p>&#x4F60;&#x7684;&#x7F51;&#x9875;&#x6027;&#x80FD;&#x4F18;&#x5316;&#x7684;&#x518D;&#x597D;&#xFF0C;&#x5982;&#x679C;&#x7F51;&#x7EDC;&#x4E0D;&#x597D;&#x90A3;&#x4E5F;&#x4F1A;&#x5BFC;&#x81F4;&#x7F51;&#x9875;&#x7684;&#x4F53;&#x9A8C;&#x5DEE;&#x3002;
&#x79BB;&#x7EBF;&#x5E94;&#x7528;&#x662F;&#x6307;&#x901A;&#x8FC7;&#x79BB;&#x7EBF;&#x7F13;&#x5B58;&#x6280;&#x672F;&#xFF0C;&#x8BA9;&#x8D44;&#x6E90;&#x5728;&#x7B2C;&#x4E00;&#x6B21;&#x88AB;&#x52A0;&#x8F7D;&#x540E;&#x7F13;&#x5B58;&#x5728;&#x672C;&#x5730;&#xFF0C;&#x4E0B;&#x6B21;&#x8BBF;&#x95EE;&#x5B83;&#x65F6;&#x5C31;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;&#x672C;&#x5730;&#x7684;&#x6587;&#x4EF6;&#xFF0C;&#x5C31;&#x7B97;&#x6CA1;&#x6709;&#x7F51;&#x7EDC;&#x8FDE;&#x63A5;&#x3002;</p>
<p>&#x79BB;&#x7EBF;&#x5E94;&#x7528;&#x6709;&#x4EE5;&#x4E0B;&#x4F18;&#x70B9;&#xFF1A;</p>
<ul>
<li>&#x5728;&#x6CA1;&#x6709;&#x7F51;&#x7EDC;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x4E5F;&#x80FD;&#x6253;&#x5F00;&#x7F51;&#x9875;&#x3002;</li>
<li>&#x7531;&#x4E8E;&#x90E8;&#x5206;&#x88AB;&#x7F13;&#x5B58;&#x7684;&#x8D44;&#x6E90;&#x76F4;&#x63A5;&#x4ECE;&#x672C;&#x5730;&#x52A0;&#x8F7D;&#xFF0C;&#x5BF9;&#x7528;&#x6237;&#x6765;&#x8BF4;&#x53EF;&#x4EE5;&#x52A0;&#x901F;&#x7F51;&#x9875;&#x52A0;&#x8F7D;&#x901F;&#x5EA6;&#xFF0C;&#x5BF9;&#x7F51;&#x7AD9;&#x8FD0;&#x8425;&#x8005;&#x6765;&#x8BF4;&#x53EF;&#x4EE5;&#x51CF;&#x5C11;&#x670D;&#x52A1;&#x5668;&#x538B;&#x529B;&#x4EE5;&#x53CA;&#x4F20;&#x8F93;&#x6D41;&#x91CF;&#x8D39;&#x7528;&#x3002;</li>
</ul>
<p>&#x79BB;&#x7EBF;&#x5E94;&#x7528;&#x7684;&#x6838;&#x5FC3;&#x662F;&#x79BB;&#x7EBF;&#x7F13;&#x5B58;&#x6280;&#x672F;&#xFF0C;&#x5386;&#x53F2;&#x4E0A;&#x66FE;&#x5148;&#x540E;&#x51FA;&#x73B0;2&#x79CD;&#x79BB;&#x7EBF;&#x79BB;&#x7EBF;&#x7F13;&#x5B58;&#x6280;&#x672F;&#xFF0C;&#x5B83;&#x4EEC;&#x5206;&#x522B;&#x662F;&#xFF1A;</p>
<ol>
<li><a href="https://developer.mozilla.org/zh-CN/docs/Web/HTML/Using_the_application_cache" target="_blank">AppCache</a> &#x53C8;&#x53EB; Application Cache&#xFF0C;&#x76EE;&#x524D;&#x5DF2;&#x7ECF;&#x4ECE; Web &#x6807;&#x51C6;&#x4E2D;&#x5220;&#x9664;&#xFF0C;&#x8BF7;&#x5C3D;&#x91CF;&#x4E0D;&#x8981;&#x4F7F;&#x7528;&#x5B83;&#x3002;</li>
<li><a href="https://developer.mozilla.org/zh-CN/docs/Web/API/Service_Worker_API/Using_Service_Workers" target="_blank">Service Workers</a> &#x662F;&#x76EE;&#x524D;&#x6700;&#x65B0;&#x7684;&#x79BB;&#x7EBF;&#x7F13;&#x5B58;&#x6280;&#x672F;&#xFF0C;&#x662F; <a href="http://javascript.ruanyifeng.com/htmlapi/webworker.html" target="_blank">Web Worker</a> &#x7684;&#x4E00;&#x90E8;&#x5206;&#x3002;
&#x5B83;&#x901A;&#x8FC7;&#x62E6;&#x622A;&#x7F51;&#x7EDC;&#x8BF7;&#x6C42;&#x5B9E;&#x73B0;&#x79BB;&#x7EBF;&#x7F13;&#x5B58;&#xFF0C;&#x6BD4; AppCache &#x66F4;&#x52A0;&#x7075;&#x6D3B;&#x3002;&#x5B83;&#x4E5F;&#x662F;&#x6784;&#x5EFA; <a href="https://developer.mozilla.org/zh-CN/Apps/Progressive" target="_blank">PWA</a> &#x5E94;&#x7528;&#x7684;&#x5173;&#x952E;&#x6280;&#x672F;&#x4E4B;&#x4E00;&#x3002;</li>
</ol>
<p>Service Workers &#x76F8;&#x6BD4;&#x4E8E; AppCache &#x6765;&#x8BF4;&#x66F4;&#x52A0;&#x7075;&#x6D3B;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; JavaScript &#x4EE3;&#x7801;&#x53BB;&#x63A7;&#x5236;&#x7F13;&#x5B58;&#x7684;&#x903B;&#x8F91;&#x3002;
&#x7531;&#x4E8E;&#x7B2C;1&#x79CD;&#x6280;&#x672F;&#x5DF2;&#x7ECF;&#x5E9F;&#x5F03;&#xFF0C;&#x672C;&#x8282;&#x53EA;&#x4E13;&#x6CE8;&#x4E8E;&#x8BB2;&#x89E3;&#x5982;&#x4F55;&#x7528; Webpack &#x6784;&#x5EFA;&#x4F7F;&#x7528;&#x4E86; Service Workers &#x7684;&#x7F51;&#x9875;&#x3002;</p>
<h2 id="&#x8BA4;&#x8BC6;-service-workers">&#x8BA4;&#x8BC6; Service Workers</h2>
<p>Service Workers &#x662F;&#x4E00;&#x4E2A;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x540E;&#x53F0;&#x8FD0;&#x884C;&#x7684;&#x811A;&#x672C;&#xFF0C;&#x5B83;&#x751F;&#x547D;&#x5468;&#x671F;&#x5B8C;&#x5168;&#x72EC;&#x7ACB;&#x4E8E;&#x7F51;&#x9875;&#x3002;&#x5B83;&#x65E0;&#x6CD5;&#x76F4;&#x63A5;&#x8BBF;&#x95EE; DOM&#xFF0C;&#x4F46;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; postMessage &#x63A5;&#x53E3;&#x53D1;&#x9001;&#x6D88;&#x606F;&#x6765;&#x548C; UI &#x8FDB;&#x7A0B;&#x901A;&#x4FE1;&#x3002;
&#x62E6;&#x622A;&#x7F51;&#x7EDC;&#x8BF7;&#x6C42;&#x662F; Service Workers &#x7684;&#x4E00;&#x4E2A;&#x91CD;&#x8981;&#x529F;&#x80FD;&#xFF0C;&#x901A;&#x8FC7;&#x5B83;&#x80FD;&#x5B8C;&#x6210;&#x79BB;&#x7EBF;&#x7F13;&#x5B58;&#x3001;&#x7F16;&#x8F91;&#x54CD;&#x5E94;&#x3001;&#x8FC7;&#x6EE4;&#x54CD;&#x5E94;&#x7B49;&#x529F;&#x80FD;&#x3002;</p>
<p>&#x60F3;&#x66F4;&#x6DF1;&#x5165;&#x7684;&#x4E86;&#x89E3; Service Workers&#xFF0C;&#x63A8;&#x8350;&#x9605;&#x8BFB;&#x6587;&#x7AE0;<a href="https://developers.google.com/web/fundamentals/getting-started/primers/service-workers?hl=zh-cn" target="_blank">&#x670D;&#x52A1;&#x5DE5;&#x4F5C;&#x7EBF;&#x7A0B;&#xFF1A;&#x7B80;&#x4ECB;</a>&#x3002;</p>
<h3 id="service-workers-&#x517C;&#x5BB9;&#x6027;">Service Workers &#x517C;&#x5BB9;&#x6027;</h3>
<p>&#x76EE;&#x524D; Chrome&#x3001;Firefox&#x3001;Opera &#x90FD;&#x5DF2;&#x7ECF;&#x5168;&#x9762;&#x652F;&#x6301; Service Workers&#xFF0C;&#x4F46;&#x5BF9;&#x4E8E;&#x79FB;&#x52A8;&#x7AEF;&#x6D4F;&#x89C8;&#x5668;&#x5C31;&#x4E0D;&#x592A;&#x4E50;&#x89C2;&#x4E86;&#xFF0C;&#x53EA;&#x6709;&#x9AD8;&#x7248;&#x672C;&#x7684; Android &#x652F;&#x6301;&#x3002;
&#x7531;&#x4E8E; Service Workers &#x65E0;&#x6CD5;&#x901A;&#x8FC7;&#x6CE8;&#x5165; polyfill &#x53BB;&#x5B9E;&#x73B0;&#x517C;&#x5BB9;&#xFF0C;&#x6240;&#x4EE5;&#x5728;&#x4F60;&#x6253;&#x7B97;&#x4F7F;&#x7528;&#x5B83;&#x524D;&#x8BF7;&#x5148;&#x8C03;&#x67E5;&#x6E05;&#x695A;&#x4F60;&#x7684;&#x7F51;&#x9875;&#x7684;&#x8FD0;&#x884C;&#x573A;&#x666F;&#x3002;</p>
<p>&#x5224;&#x65AD;&#x6D4F;&#x89C8;&#x5668;&#x662F;&#x5426;&#x652F;&#x6301; Service Workers &#x7684;&#x6700;&#x7B80;&#x5355;&#x7684;&#x65B9;&#x6CD5;&#x662F;&#x901A;&#x8FC7;&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x5982;&#x679C; navigator &#x5BF9;&#x8C61;&#x4E0A;&#x5B58;&#x5728; serviceWorker &#x5BF9;&#x8C61;&#xFF0C;&#x5C31;&#x8868;&#x793A;&#x652F;&#x6301;</span>
<span class="hljs-keyword">if</span> (navigator.serviceWorker) {
  <span class="hljs-comment">// &#x901A;&#x8FC7; navigator.serviceWorker &#x4F7F;&#x7528;</span>
}
</code></pre>
<h3 id="&#x6CE8;&#x518C;-service-workers">&#x6CE8;&#x518C; Service Workers</h3>
<p>&#x8981;&#x7ED9;&#x7F51;&#x9875;&#x63A5;&#x5165; Service Workers&#xFF0C;&#x9700;&#x8981;&#x5728;&#x7F51;&#x9875;&#x52A0;&#x8F7D;&#x540E;&#x6CE8;&#x518C;&#x4E00;&#x4E2A;&#x63CF;&#x8FF0; Service Workers &#x903B;&#x8F91;&#x7684;&#x811A;&#x672C;&#x3002;
&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">if</span> (navigator.serviceWorker) {
  <span class="hljs-built_in">window</span>.addEventListener(<span class="hljs-string">&apos;DOMContentLoaded&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// &#x8C03;&#x7528; serviceWorker.register &#x6CE8;&#x518C;&#xFF0C;&#x53C2;&#x6570; /sw.js &#x4E3A;&#x811A;&#x672C;&#x6587;&#x4EF6;&#x6240;&#x5728;&#x7684; URL &#x8DEF;&#x5F84;</span>
      navigator.serviceWorker.register(<span class="hljs-string">&apos;/sw.js&apos;</span>);
  });
}
</code></pre>
<p>&#x4E00;&#x65E6;&#x8FD9;&#x4E2A;&#x811A;&#x672C;&#x6587;&#x4EF6;&#x88AB;&#x52A0;&#x8F7D;&#xFF0C;Service Workers &#x7684;&#x5B89;&#x88C5;&#x5C31;&#x5F00;&#x59CB;&#x4E86;&#x3002;&#x8FD9;&#x4E2A;&#x811A;&#x672C;&#x88AB;&#x5B89;&#x88C5;&#x5230;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x540E;&#xFF0C;&#x5C31;&#x7B97;&#x7528;&#x6237;&#x5173;&#x95ED;&#x4E86;&#x5F53;&#x524D;&#x7F51;&#x9875;&#xFF0C;&#x5B83;&#x4ECD;&#x4F1A;&#x5B58;&#x5728;&#x3002;
&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x7B2C;&#x4E00;&#x6B21;&#x6253;&#x5F00;&#x8BE5;&#x7F51;&#x9875;&#x65F6; Service Workers &#x7684;&#x903B;&#x8F91;&#x4E0D;&#x4F1A;&#x751F;&#x6548;&#xFF0C;&#x56E0;&#x4E3A;&#x811A;&#x672C;&#x8FD8;&#x6CA1;&#x6709;&#x88AB;&#x52A0;&#x8F7D;&#x548C;&#x6CE8;&#x518C;&#xFF0C;&#x4F46;&#x662F;&#x4EE5;&#x540E;&#x518D;&#x6B21;&#x6253;&#x5F00;&#x8BE5;&#x7F51;&#x9875;&#x65F6;&#x811A;&#x672C;&#x91CC;&#x7684;&#x903B;&#x8F91;&#x5C06;&#x4F1A;&#x751F;&#x6548;&#x3002;</p>
<p>&#x5728; Chrome &#x4E2D;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6253;&#x5F00;&#x7F51;&#x5740; <code>chrome://inspect/#service-workers</code> &#x6765;&#x67E5;&#x770B;&#x5F53;&#x524D;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x6240;&#x6709;&#x6CE8;&#x518C;&#x4E86;&#x7684; Service Workers&#x3002;</p>
<h3 id="&#x4F7F;&#x7528;-service-workers-&#x5B9E;&#x73B0;&#x79BB;&#x7EBF;&#x7F13;&#x5B58;">&#x4F7F;&#x7528; Service Workers &#x5B9E;&#x73B0;&#x79BB;&#x7EBF;&#x7F13;&#x5B58;</h3>
<p>Service Workers &#x5728;&#x6CE8;&#x518C;&#x6210;&#x529F;&#x540E;&#x4F1A;&#x5728;&#x5176;&#x751F;&#x547D;&#x5468;&#x671F;&#x4E2D;&#x6D3E;&#x53D1;&#x51FA;&#x4E00;&#x4E9B;&#x4E8B;&#x4EF6;&#xFF0C;&#x901A;&#x8FC7;&#x76D1;&#x542C;&#x5BF9;&#x5E94;&#x7684;&#x4E8B;&#x4EF6;&#x5728;&#x7279;&#x70B9;&#x7684;&#x65F6;&#x95F4;&#x8282;&#x70B9;&#x4E0A;&#x505A;&#x4E00;&#x4E9B;&#x4E8B;&#x60C5;&#x3002;</p>
<p>&#x5728; Service Workers &#x811A;&#x672C;&#x4E2D;&#xFF0C;&#x5F15;&#x5165;&#x4E86;&#x65B0;&#x7684;&#x5173;&#x952E;&#x5B57; <code>self</code> &#x4EE3;&#x8868;&#x5F53;&#x524D;&#x7684; Service Workers &#x5B9E;&#x4F8B;&#x3002;</p>
<p>&#x5728; Service Workers &#x5B89;&#x88C5;&#x6210;&#x529F;&#x540E;&#x4F1A;&#x6D3E;&#x53D1;&#x51FA; <code>install</code> &#x4E8B;&#x4EF6;&#xFF0C;&#x9700;&#x8981;&#x5728;&#x8FD9;&#x4E2A;&#x4E8B;&#x4EF6;&#x4E2D;&#x6267;&#x884C;&#x7F13;&#x5B58;&#x8D44;&#x6E90;&#x7684;&#x903B;&#x8F91;&#xFF0C;&#x5B9E;&#x73B0;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x5F53;&#x524D;&#x7F13;&#x5B58;&#x7248;&#x672C;&#x7684;&#x552F;&#x4E00;&#x6807;&#x8BC6;&#x7B26;&#xFF0C;&#x7528;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x4EE3;&#x66FF;</span>
<span class="hljs-keyword">var</span> cacheKey = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().toISOString();

<span class="hljs-comment">// &#x9700;&#x8981;&#x88AB;&#x7F13;&#x5B58;&#x7684;&#x6587;&#x4EF6;&#x7684; URL &#x5217;&#x8868;</span>
<span class="hljs-keyword">var</span> cacheFileList = [
  <span class="hljs-string">&apos;/index.html&apos;</span>,
  <span class="hljs-string">&apos;/app.js&apos;</span>,
  <span class="hljs-string">&apos;/app.css&apos;</span>
];

<span class="hljs-comment">// &#x76D1;&#x542C; install &#x4E8B;&#x4EF6;</span>
self.addEventListener(<span class="hljs-string">&apos;install&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">event</span>) </span>{
  <span class="hljs-comment">// &#x7B49;&#x5F85;&#x6240;&#x6709;&#x8D44;&#x6E90;&#x7F13;&#x5B58;&#x5B8C;&#x6210;&#x65F6;&#xFF0C;&#x624D;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x4E0B;&#x4E00;&#x6B65;</span>
  event.waitUntil(
    caches.open(cacheKey).then(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">cache</span>) </span>{
      <span class="hljs-comment">// &#x8981;&#x7F13;&#x5B58;&#x7684;&#x6587;&#x4EF6; URL &#x5217;&#x8868;</span>
      <span class="hljs-keyword">return</span> cache.addAll(cacheFileList);
    })
  );
});
</code></pre>
<p>&#x63A5;&#x4E0B;&#x6765;&#x9700;&#x8981;&#x76D1;&#x542C;&#x7F51;&#x7EDC;&#x8BF7;&#x6C42;&#x4E8B;&#x4EF6;&#x53BB;&#x62E6;&#x622A;&#x8BF7;&#x6C42;&#xFF0C;&#x590D;&#x7528;&#x7F13;&#x5B58;&#xFF0C;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js">self.addEventListener(<span class="hljs-string">&apos;fetch&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">event</span>) </span>{
  event.respondWith(
    <span class="hljs-comment">// &#x53BB;&#x7F13;&#x5B58;&#x4E2D;&#x67E5;&#x8BE2;&#x5BF9;&#x5E94;&#x7684;&#x8BF7;&#x6C42;</span>
    caches.match(event.request).then(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">response</span>) </span>{
        <span class="hljs-comment">// &#x5982;&#x679C;&#x547D;&#x4E2D;&#x672C;&#x5730;&#x7F13;&#x5B58;&#xFF0C;&#x5C31;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;&#x672C;&#x5730;&#x7684;&#x8D44;&#x6E90;</span>
        <span class="hljs-keyword">if</span> (response) {
          <span class="hljs-keyword">return</span> response;
        }
        <span class="hljs-comment">// &#x5426;&#x5219;&#x5C31;&#x53BB;&#x7528; fetch &#x4E0B;&#x8F7D;&#x8D44;&#x6E90;</span>
        <span class="hljs-keyword">return</span> fetch(event.request);
      }
    )
  );
});
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x5C31;&#x5B9E;&#x73B0;&#x4E86;&#x79BB;&#x7EBF;&#x7F13;&#x5B58;&#x3002;</p>
<h3 id="&#x66F4;&#x65B0;&#x7F13;&#x5B58;">&#x66F4;&#x65B0;&#x7F13;&#x5B58;</h3>
<p>&#x7EBF;&#x4E0A;&#x7684;&#x4EE3;&#x7801;&#x6709;&#x65F6;&#x9700;&#x8981;&#x66F4;&#x65B0;&#x548C;&#x91CD;&#x65B0;&#x53D1;&#x5E03;&#xFF0C;&#x5982;&#x679C;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x88AB;&#x79BB;&#x7EBF;&#x7F13;&#x5B58;&#x4E86;&#xFF0C;&#x90A3;&#x5C31;&#x9700;&#x8981; Service Workers &#x811A;&#x672C;&#x4E2D;&#x6709;&#x5BF9;&#x5E94;&#x7684;&#x903B;&#x8F91;&#x53BB;&#x66F4;&#x65B0;&#x7F13;&#x5B58;&#x3002;
&#x8FD9;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x66F4;&#x65B0; Service Workers &#x811A;&#x672C;&#x6587;&#x4EF6;&#x505A;&#x5230;&#x3002;</p>
<p>&#x6D4F;&#x89C8;&#x5668;&#x9488;&#x5BF9; Service Workers &#x6709;&#x5982;&#x4E0B;&#x673A;&#x5236;&#xFF1A;</p>
<ol>
<li>&#x6BCF;&#x6B21;&#x6253;&#x5F00;&#x63A5;&#x5165;&#x4E86; Service Workers &#x7684;&#x7F51;&#x9875;&#x65F6;&#xFF0C;&#x6D4F;&#x89C8;&#x5668;&#x90FD;&#x4F1A;&#x53BB;&#x91CD;&#x65B0;&#x4E0B;&#x8F7D; Service Workers &#x811A;&#x672C;&#x6587;&#x4EF6;&#xFF08;&#x6240;&#x4EE5;&#x8981;&#x6CE8;&#x610F;&#x8BE5;&#x811A;&#x672C;&#x6587;&#x4EF6;&#x4E0D;&#x80FD;&#x592A;&#x5927;&#xFF09;&#xFF0C;&#x5982;&#x679C;&#x53D1;&#x73B0;&#x548C;&#x5F53;&#x524D;&#x5DF2;&#x7ECF;&#x6CE8;&#x518C;&#x8FC7;&#x7684;&#x6587;&#x4EF6;&#x5B58;&#x5728;&#x5B57;&#x8282;&#x5DEE;&#x5F02;&#xFF0C;&#x5C31;&#x5C06;&#x5176;&#x89C6;&#x4E3A;&#x201C;&#x65B0;&#x670D;&#x52A1;&#x5DE5;&#x4F5C;&#x7EBF;&#x7A0B;&#x201D;&#x3002;</li>
<li>&#x65B0; Service Workers &#x7EBF;&#x7A0B;&#x5C06;&#x4F1A;&#x542F;&#x52A8;&#xFF0C;&#x4E14;&#x5C06;&#x4F1A;&#x89E6;&#x53D1;&#x5176; install &#x4E8B;&#x4EF6;&#x3002;</li>
<li>&#x5F53;&#x7F51;&#x7AD9;&#x4E0A;&#x5F53;&#x524D;&#x6253;&#x5F00;&#x7684;&#x9875;&#x9762;&#x5173;&#x95ED;&#x65F6;&#xFF0C;&#x65E7; Service Workers &#x7EBF;&#x7A0B;&#x5C06;&#x4F1A;&#x88AB;&#x7EC8;&#x6B62;&#xFF0C;&#x65B0; Service Workers &#x7EBF;&#x7A0B;&#x5C06;&#x4F1A;&#x53D6;&#x5F97;&#x63A7;&#x5236;&#x6743;&#x3002;</li>
<li>&#x65B0; Service Workers &#x7EBF;&#x7A0B;&#x53D6;&#x5F97;&#x63A7;&#x5236;&#x6743;&#x540E;&#xFF0C;&#x5C06;&#x4F1A;&#x89E6;&#x53D1;&#x5176; activate &#x4E8B;&#x4EF6;&#x3002;</li>
</ol>
<p>&#x65B0; Service Workers &#x7EBF;&#x7A0B;&#x4E2D;&#x7684; activate &#x4E8B;&#x4EF6;&#x5C31;&#x662F;&#x6700;&#x4F73;&#x7684;&#x6E05;&#x7406;&#x65E7;&#x7F13;&#x5B58;&#x7684;&#x65F6;&#x95F4;&#x70B9;&#xFF0C;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x5F53;&#x524D;&#x7F13;&#x5B58;&#x767D;&#x540D;&#x5355;&#xFF0C;&#x5728;&#x65B0;&#x811A;&#x672C;&#x7684; install &#x4E8B;&#x4EF6;&#x91CC;&#x5C06;&#x4F7F;&#x7528;&#x767D;&#x540D;&#x5355;&#x91CC;&#x7684; key </span>
<span class="hljs-keyword">var</span> cacheWhitelist = [cacheKey];

self.addEventListener(<span class="hljs-string">&apos;activate&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">event</span>) </span>{
  event.waitUntil(
    caches.keys().then(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">cacheNames</span>) </span>{
      <span class="hljs-keyword">return</span> <span class="hljs-built_in">Promise</span>.all(
        cacheNames.map(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">cacheName</span>) </span>{
          <span class="hljs-comment">// &#x4E0D;&#x5728;&#x767D;&#x540D;&#x5355;&#x7684;&#x7F13;&#x5B58;&#x5168;&#x90E8;&#x6E05;&#x7406;&#x6389;</span>
          <span class="hljs-keyword">if</span> (cacheWhitelist.indexOf(cacheName) === <span class="hljs-number">-1</span>) {
            <span class="hljs-comment">// &#x5220;&#x9664;&#x7F13;&#x5B58;</span>
            <span class="hljs-keyword">return</span> caches.delete(cacheName);
          }
        })
      );
    })
  );
});
</code></pre>
<p>&#x6700;&#x7EC8;&#x5B8C;&#x6574;&#x7684;&#x4EE3;&#x7801; Service Workers &#x811A;&#x672C;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x5F53;&#x524D;&#x7F13;&#x5B58;&#x7248;&#x672C;&#x7684;&#x552F;&#x4E00;&#x6807;&#x8BC6;&#x7B26;&#xFF0C;&#x7528;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x4EE3;&#x66FF;</span>
<span class="hljs-keyword">var</span> cacheKey = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().toISOString();

<span class="hljs-comment">// &#x5F53;&#x524D;&#x7F13;&#x5B58;&#x767D;&#x540D;&#x5355;&#xFF0C;&#x5728;&#x65B0;&#x811A;&#x672C;&#x7684; install &#x4E8B;&#x4EF6;&#x91CC;&#x5C06;&#x4F7F;&#x7528;&#x767D;&#x540D;&#x5355;&#x91CC;&#x7684; key</span>
<span class="hljs-keyword">var</span> cacheWhitelist = [cacheKey];

<span class="hljs-comment">// &#x9700;&#x8981;&#x88AB;&#x7F13;&#x5B58;&#x7684;&#x6587;&#x4EF6;&#x7684; URL &#x5217;&#x8868;</span>
<span class="hljs-keyword">var</span> cacheFileList = [
  <span class="hljs-string">&apos;/index.html&apos;</span>,
  <span class="hljs-string">&apos;app.js&apos;</span>,
  <span class="hljs-string">&apos;app.css&apos;</span>
];

<span class="hljs-comment">// &#x76D1;&#x542C; install &#x4E8B;&#x4EF6;</span>
self.addEventListener(<span class="hljs-string">&apos;install&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">event</span>) </span>{
  <span class="hljs-comment">// &#x7B49;&#x5F85;&#x6240;&#x6709;&#x8D44;&#x6E90;&#x7F13;&#x5B58;&#x5B8C;&#x6210;&#x65F6;&#xFF0C;&#x624D;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x4E0B;&#x4E00;&#x6B65;</span>
  event.waitUntil(
    caches.open(cacheKey).then(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">cache</span>) </span>{
      <span class="hljs-comment">// &#x8981;&#x7F13;&#x5B58;&#x7684;&#x6587;&#x4EF6; URL &#x5217;&#x8868;</span>
      <span class="hljs-keyword">return</span> cache.addAll(cacheFileList);
    })
  );
});

<span class="hljs-comment">// &#x62E6;&#x622A;&#x7F51;&#x7EDC;&#x8BF7;&#x6C42;</span>
self.addEventListener(<span class="hljs-string">&apos;fetch&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">event</span>) </span>{
  event.respondWith(
    <span class="hljs-comment">// &#x53BB;&#x7F13;&#x5B58;&#x4E2D;&#x67E5;&#x8BE2;&#x5BF9;&#x5E94;&#x7684;&#x8BF7;&#x6C42;</span>
    caches.match(event.request).then(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">response</span>) </span>{
        <span class="hljs-comment">// &#x5982;&#x679C;&#x547D;&#x4E2D;&#x672C;&#x5730;&#x7F13;&#x5B58;&#xFF0C;&#x5C31;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;&#x672C;&#x5730;&#x7684;&#x8D44;&#x6E90;</span>
        <span class="hljs-keyword">if</span> (response) {
          <span class="hljs-keyword">return</span> response;
        }
        <span class="hljs-comment">// &#x5426;&#x5219;&#x5C31;&#x53BB;&#x7528; fetch &#x4E0B;&#x8F7D;&#x8D44;&#x6E90;</span>
        <span class="hljs-keyword">return</span> fetch(event.request);
      }
    )
  );
});

<span class="hljs-comment">// &#x65B0; Service Workers &#x7EBF;&#x7A0B;&#x53D6;&#x5F97;&#x63A7;&#x5236;&#x6743;&#x540E;&#xFF0C;&#x5C06;&#x4F1A;&#x89E6;&#x53D1;&#x5176; activate &#x4E8B;&#x4EF6;</span>
self.addEventListener(<span class="hljs-string">&apos;activate&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">event</span>) </span>{
  event.waitUntil(
    caches.keys().then(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">cacheNames</span>) </span>{
      <span class="hljs-keyword">return</span> <span class="hljs-built_in">Promise</span>.all(
        cacheNames.map(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">cacheName</span>) </span>{
          <span class="hljs-comment">// &#x4E0D;&#x5728;&#x767D;&#x540D;&#x5355;&#x7684;&#x7F13;&#x5B58;&#x5168;&#x90E8;&#x6E05;&#x7406;&#x6389;</span>
          <span class="hljs-keyword">if</span> (cacheWhitelist.indexOf(cacheName) === <span class="hljs-number">-1</span>) {
            <span class="hljs-comment">// &#x5220;&#x9664;&#x7F13;&#x5B58;</span>
            <span class="hljs-keyword">return</span> caches.delete(cacheName);
          }
        })
      );
    })
  );
});
</code></pre>
<h2 id="&#x63A5;&#x5165;-webpack">&#x63A5;&#x5165; Webpack</h2>
<p>&#x7528; Webpack &#x6784;&#x5EFA;&#x63A5;&#x5165; Service Workers &#x7684;&#x79BB;&#x7EBF;&#x5E94;&#x7528;&#x8981;&#x89E3;&#x51B3;&#x7684;&#x5173;&#x952E;&#x95EE;&#x9898;&#x5728;&#x4E8E;&#x5982;&#x4F55;&#x751F;&#x6210;&#x4E0A;&#x9762;&#x63D0;&#x5230;&#x7684; <code>sw.js</code> &#x6587;&#x4EF6;&#xFF0C;
&#x5E76;&#x4E14;<code>sw.js</code>&#x6587;&#x4EF6;&#x4E2D;&#x7684; <code>cacheFileList</code> &#x53D8;&#x91CF;&#xFF0C;&#x4EE3;&#x8868;&#x9700;&#x8981;&#x88AB;&#x7F13;&#x5B58;&#x6587;&#x4EF6;&#x7684; URL &#x5217;&#x8868;&#xFF0C;&#x9700;&#x8981;&#x6839;&#x636E;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x5217;&#x8868;&#x6240;&#x5BF9;&#x5E94;&#x7684; URL &#x6765;&#x51B3;&#x5B9A;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x50CF;&#x4E0A;&#x9762;&#x90A3;&#x6837;&#x5199;&#x6210;&#x9759;&#x6001;&#x503C;&#x3002;</p>
<p>&#x5047;&#x5982;&#x6784;&#x5EFA;&#x8F93;&#x51FA;&#x7684;&#x6587;&#x4EF6;&#x76EE;&#x5F55;&#x7ED3;&#x6784;&#x4E3A;&#xFF1A;</p>
<pre><code>&#x251C;&#x2500;&#x2500; app_4c3e186f.js
&#x251C;&#x2500;&#x2500; app_7cc98ad0.css
&#x2514;&#x2500;&#x2500; index.html
</code></pre><p>&#x90A3;&#x4E48; <code>sw.js</code> &#x6587;&#x4EF6;&#x4E2D; <code>cacheFileList</code> &#x7684;&#x503C;&#x5E94;&#x8BE5;&#x662F;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> cacheFileList = [
  <span class="hljs-string">&apos;/index.html&apos;</span>,
  <span class="hljs-string">&apos;app_4c3e186f.js&apos;</span>,
  <span class="hljs-string">&apos;app_7cc98ad0.css&apos;</span>
];
</code></pre>
<p>Webpack &#x6CA1;&#x6709;&#x539F;&#x751F;&#x529F;&#x80FD;&#x80FD;&#x5B8C;&#x6210;&#x4EE5;&#x4E0A;&#x8981;&#x6C42;&#xFF0C;&#x5E78;&#x597D;&#x5E9E;&#x5927;&#x7684;&#x793E;&#x533A;&#x4E2D;&#x5DF2;&#x7ECF;&#x6709;&#x4EBA;&#x4E3A;&#x6211;&#x4EEC;&#x505A;&#x597D;&#x4E86;&#x4E00;&#x4E2A;&#x63D2;&#x4EF6; <a href="https://github.com/oliviertassinari/serviceworker-webpack-plugin" target="_blank">serviceworker-webpack-plugin</a> &#x53EF;&#x4EE5;&#x65B9;&#x4FBF;&#x7684;&#x89E3;&#x51B3;&#x4EE5;&#x4E0A;&#x95EE;&#x9898;&#x3002;
&#x4F7F;&#x7528;&#x8BE5;&#x63D2;&#x4EF6;&#x540E;&#x7684; Webpack &#x914D;&#x7F6E;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);
<span class="hljs-keyword">const</span> ExtractTextPlugin = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;extract-text-webpack-plugin&apos;</span>);
<span class="hljs-keyword">const</span> { WebPlugin } = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;web-webpack-plugin&apos;</span>);
<span class="hljs-keyword">const</span> ServiceWorkerWebpackPlugin = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;serviceworker-webpack-plugin&apos;</span>);

<span class="hljs-built_in">module</span>.exports = {
  entry: {
    app: <span class="hljs-string">&apos;./main.js&apos;</span><span class="hljs-comment">// Chunk app &#x7684; JS &#x6267;&#x884C;&#x5165;&#x53E3;&#x6587;&#x4EF6;</span>
  },
  output: {
    filename: <span class="hljs-string">&apos;[name].js&apos;</span>,
    publicPath: <span class="hljs-string">&apos;&apos;</span>,
  },
  <span class="hljs-built_in">module</span>: {
    rules: [
      {
        test: <span class="hljs-regexp">/\.css/</span>,<span class="hljs-comment">// &#x589E;&#x52A0;&#x5BF9; CSS &#x6587;&#x4EF6;&#x7684;&#x652F;&#x6301;</span>
        <span class="hljs-comment">// &#x63D0;&#x53D6;&#x51FA; Chunk &#x4E2D;&#x7684; CSS &#x4EE3;&#x7801;&#x5230;&#x5355;&#x72EC;&#x7684;&#x6587;&#x4EF6;&#x4E2D;</span>
        use: ExtractTextPlugin.extract({
          use: [<span class="hljs-string">&apos;css-loader&apos;</span>] <span class="hljs-comment">// &#x538B;&#x7F29; CSS &#x4EE3;&#x7801;</span>
        }),
      },
    ]
  },
  plugins: [
    <span class="hljs-comment">// &#x4E00;&#x4E2A; WebPlugin &#x5BF9;&#x5E94;&#x4E00;&#x4E2A; HTML &#x6587;&#x4EF6;</span>
    <span class="hljs-keyword">new</span> WebPlugin({
      template: <span class="hljs-string">&apos;./template.html&apos;</span>, <span class="hljs-comment">// HTML &#x6A21;&#x7248;&#x6587;&#x4EF6;&#x6240;&#x5728;&#x7684;&#x6587;&#x4EF6;&#x8DEF;&#x5F84;</span>
      filename: <span class="hljs-string">&apos;index.html&apos;</span> <span class="hljs-comment">// &#x8F93;&#x51FA;&#x7684; HTML &#x7684;&#x6587;&#x4EF6;&#x540D;&#x79F0;</span>
    }),
    <span class="hljs-keyword">new</span> ExtractTextPlugin({
      filename: <span class="hljs-string">`[name].css`</span>,<span class="hljs-comment">// &#x7ED9;&#x8F93;&#x51FA;&#x7684; CSS &#x6587;&#x4EF6;&#x540D;&#x79F0;&#x52A0;&#x4E0A; Hash &#x503C;</span>
    }),
    <span class="hljs-keyword">new</span> ServiceWorkerWebpackPlugin({
      <span class="hljs-comment">// &#x81EA;&#x5B9A;&#x4E49;&#x7684; sw.js &#x6587;&#x4EF6;&#x6240;&#x5728;&#x8DEF;&#x5F84;</span>
      <span class="hljs-comment">// ServiceWorkerWebpackPlugin &#x4F1A;&#x628A;&#x6587;&#x4EF6;&#x5217;&#x8868;&#x6CE8;&#x5165;&#x5230;&#x751F;&#x6210;&#x7684; sw.js &#x4E2D;</span>
      entry: path.join(__dirname, <span class="hljs-string">&apos;sw.js&apos;</span>),
    }),
  ],
  devServer: {
    <span class="hljs-comment">// Service Workers &#x4F9D;&#x8D56; HTTPS&#xFF0C;&#x4F7F;&#x7528; DevServer &#x63D0;&#x4F9B;&#x7684; HTTPS &#x529F;&#x80FD;&#x3002;</span>
    https: <span class="hljs-literal">true</span>,
  }
};
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x914D;&#x7F6E;&#x6709;2&#x70B9;&#x9700;&#x8981;&#x6CE8;&#x610F;&#xFF1A;</p>
<ul>
<li>&#x7531;&#x4E8E; Service Workers &#x5FC5;&#x987B;&#x5728; HTTPS &#x73AF;&#x5883;&#x4E0B;&#x624D;&#x80FD;&#x62E6;&#x622A;&#x7F51;&#x7EDC;&#x8BF7;&#x6C42;&#x5B9E;&#x73B0;&#x79BB;&#x7EBF;&#x7F13;&#x5B58;&#xFF0C;&#x4F7F;&#x7528;&#x5728; <a href="../2&#x914D;&#x7F6E;/2-6DevServer.html">2-6 DevServer https</a> &#x4E2D;&#x63D0;&#x5230;&#x7684;&#x65B9;&#x5F0F;&#x53BB;&#x5B9E;&#x73B0; HTTPS &#x670D;&#x52A1;&#x3002;</li>
<li>serviceworker-webpack-plugin &#x63D2;&#x4EF6;&#x4E3A;&#x4E86;&#x4FDD;&#x8BC1;&#x7075;&#x6D3B;&#x6027;&#xFF0C;&#x5141;&#x8BB8;&#x4F7F;&#x7528;&#x8005;&#x81EA;&#x5B9A;&#x4E49; <code>sw.js</code>&#xFF0C;&#x6784;&#x5EFA;&#x8F93;&#x51FA;&#x7684; <code>sw.js</code> &#x6587;&#x4EF6;&#x4E2D;&#x4F1A;&#x5728;&#x5934;&#x90E8;&#x6CE8;&#x5165;&#x4E00;&#x4E2A;&#x53D8;&#x91CF; <code>serviceWorkerOption.assets</code> &#x5230;&#x5168;&#x5C40;&#xFF0C;&#x91CC;&#x9762;&#x5B58;&#x653E;&#x7740;&#x6240;&#x6709;&#x9700;&#x8981;&#x88AB;&#x7F13;&#x5B58;&#x7684;&#x6587;&#x4EF6;&#x7684; URL &#x5217;&#x8868;&#x3002;</li>
</ul>
<p>&#x9700;&#x8981;&#x4FEE;&#x6539;&#x4E0A;&#x9762;&#x7684; <code>sw.js</code> &#x6587;&#x4EF6;&#x4E2D;&#x5199;&#x6210;&#x4E86;&#x9759;&#x6001;&#x503C;&#x7684; <code>cacheFileList</code> &#x4E3A;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x9700;&#x8981;&#x88AB;&#x7F13;&#x5B58;&#x7684;&#x6587;&#x4EF6;&#x7684; URL &#x5217;&#x8868;</span>
<span class="hljs-keyword">var</span> cacheFileList = global.serviceWorkerOption.assets;
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x5DF2;&#x7ECF;&#x5B8C;&#x6210;&#x6240;&#x6709;&#x6587;&#x4EF6;&#x7684;&#x4FEE;&#x6539;&#xFF0C;&#x5728;&#x91CD;&#x65B0;&#x6784;&#x5EFA;&#x524D;&#xFF0C;&#x5148;&#x5B89;&#x88C5;&#x65B0;&#x5F15;&#x5165;&#x7684;&#x4F9D;&#x8D56;&#xFF1A;</p>
<pre><code class="lang-bash">npm i -D serviceworker-webpack-plugin webpack-dev-server
</code></pre>
<p>&#x5B89;&#x88C5;&#x6210;&#x529F;&#x540E;&#xFF0C;&#x5728;&#x9879;&#x76EE;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#x6267;&#x884C; <code>webpack-dev-server</code> &#x547D;&#x4EE4;&#x540E;&#xFF0C;DevServer &#x5C06;&#x4EE5; HTTPS &#x6A21;&#x5F0F;&#x542F;&#x52A8;&#xFF0C;&#x5E76;&#x8F93;&#x51FA;&#x5982;&#x4E0B;&#x65E5;&#x5FD7;&#xFF1A;</p>
<pre><code>&gt; webpack-dev-server

Project is running at https://localhost:8080/
webpack output is served from /
Hash: 402ee6ce5bffb16dffe2
Version: webpack 3.5.5
Time: 619ms
     Asset       Size  Chunks                    Chunk Names
    app.js     325 kB       0  [emitted]  [big]  app
   app.css   21 bytes       0  [emitted]         app
index.html  235 bytes          [emitted]         
     sw.js    4.86 kB          [emitted]
</code></pre><p>&#x7528; Chrome &#x6D4F;&#x89C8;&#x5668;&#x6253;&#x5F00;&#x7F51;&#x5740; <code>https://localhost:8080/index.html</code> &#x540E;&#xFF0C;&#x5C31;&#x80FD;&#x8BBF;&#x95EE;&#x63A5;&#x5165;&#x4E86; Service Workers &#x79BB;&#x7EBF;&#x7F13;&#x5B58;&#x7684;&#x9875;&#x9762;&#x4E86;&#x3002;</p>
<h2 id="&#x9A8C;&#x8BC1;&#x7ED3;&#x679C;">&#x9A8C;&#x8BC1;&#x7ED3;&#x679C;</h2>
<p>&#x4E3A;&#x4E86;&#x9A8C;&#x8BC1; Service Workers &#x548C;&#x7F13;&#x5B58;&#x751F;&#x6548;&#x4E86;&#xFF0C;&#x9700;&#x8981;&#x901A;&#x8FC7; Chrome &#x7684;&#x5F00;&#x53D1;&#x8005;&#x5DE5;&#x5177;&#x6765;&#x67E5;&#x770B;&#x3002;</p>
<p>&#x901A;&#x8FC7;&#x6253;&#x5F00;&#x5F00;&#x53D1;&#x8005;&#x5DE5;&#x5177;&#x7684; Application-Service Workers &#x4E00;&#x680F;&#xFF0C;&#x5C31;&#x80FD;&#x770B;&#x5230;&#x5F53;&#x524D;&#x9875;&#x9762;&#x6CE8;&#x518C;&#x7684; Service Workers&#xFF0C;&#x6B63;&#x5E38;&#x7684;&#x6548;&#x679C;&#x5982;&#x56FE;&#xFF1A;</p>
<p><img src="img/3-14service-workers.png" alt="&#x56FE;3.12.1 &#x67E5;&#x770B;&#x5F53;&#x524D;&#x9875;&#x9762;&#x6CE8;&#x518C;&#x7684; Service Workers"></p>
<p>&#x901A;&#x8FC7;&#x6253;&#x5F00;&#x5F00;&#x53D1;&#x8005;&#x5DE5;&#x5177;&#x7684; Application-Cache-Cache Storage &#x4E00;&#x680F;&#xFF0C;&#x80FD;&#x770B;&#x5230;&#x5F53;&#x524D;&#x9875;&#x9762;&#x7F13;&#x5B58;&#x7684;&#x8D44;&#x6E90;&#x5217;&#x8868;&#xFF0C;&#x6B63;&#x5E38;&#x7684;&#x6548;&#x679C;&#x5982;&#x56FE;&#xFF1A;</p>
<p><img src="img/3-14cache-storage.png" alt="&#x56FE;3.12.2 &#x67E5;&#x770B;&#x5F53;&#x524D;&#x9875;&#x9762;&#x7684; Cache Storage"></p>
<p>&#x4E3A;&#x4E86;&#x9A8C;&#x8BC1;&#x7F51;&#x9875;&#x5728;&#x79BB;&#x7EBF;&#x65F6;&#x80FD;&#x8BBF;&#x95EE;&#x7684;&#x80FD;&#x529B;&#xFF0C;&#x9700;&#x8981;&#x5728;&#x5F00;&#x53D1;&#x8005;&#x5DE5;&#x5177;&#x4E2D;&#x7684; Network &#x4E00;&#x680F;&#x4E2D;&#x901A;&#x8FC7; Offline &#x9009;&#x9879;&#x7981;&#x7528;&#x6389;&#x7F51;&#x7EDC;&#xFF0C;&#x518D;&#x5237;&#x65B0;&#x9875;&#x9762;&#x80FD;&#x6B63;&#x5E38;&#x8BBF;&#x95EE;&#xFF0C;&#x5E76;&#x4E14;&#x7F51;&#x7EDC;&#x8BF7;&#x6C42;&#x7684;&#x54CD;&#x5E94;&#x90FD;&#x6765;&#x81EA; Service Workers&#xFF0C;&#x6B63;&#x5E38;&#x7684;&#x6548;&#x679C;&#x5982;&#x56FE;&#xFF1A;</p>
<p><img src="img/3-14sw-offline.png" alt="&#x56FE;3.12.3 &#x79BB;&#x7EBF;&#x60C5;&#x51B5;&#x4E0B;&#x8BBF;&#x95EE;&#x9875;&#x9762;"></p>
<blockquote>
<p>&#x672C;&#x5B9E;&#x4F8B;<a href="http://webpack.wuhaolin.cn/3-14&#x6784;&#x5EFA;&#x79BB;&#x7EBF;&#x5E94;&#x7528;.zip" target="_blank">&#x63D0;&#x4F9B;&#x9879;&#x76EE;&#x5B8C;&#x6574;&#x4EE3;&#x7801;</a></p>
</blockquote>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="3-13构建Npm模块.html" class="navigation navigation-prev " aria-label="Previous page: 3-13 构建 Npm 模块">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="3-15搭配NpmScript.html" class="navigation navigation-next " aria-label="Next page: 3-15 搭配 Npm Script">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"3-14 构建离线应用","level":"1.5.14","depth":2,"next":{"title":"3-15 搭配 Npm Script","level":"1.5.15","depth":2,"path":"3实战/3-15搭配NpmScript.md","ref":"3实战/3-15搭配NpmScript.md","articles":[]},"previous":{"title":"3-13 构建 Npm 模块","level":"1.5.13","depth":2,"path":"3实战/3-13构建Npm模块.md","ref":"3实战/3-13构建Npm模块.md","articles":[]},"dir":"ltr"},"config":{"plugins":["github-buttons","ga","modal","adsense"],"root":"./docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"search":{},"adsense":{"client":"ca-pub-9697944574373240","slot":"9319793387","format":"auto","element":".page-inner section","position":"top"},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"modal":{"closable":true,"excludeUrls":["\\?q=.+$","index.html","前言.html","\\/$","1-.+","2-2Output","3-1使用ES6语言","3-2使用TypeScript语言","3-4使用SCSS语言.html","3-5使用PostCSS.html","3-6使用React框架","3-7使用Vue框架","3-8使用Angular2框架","3-9为单页应用生成HTML","3-10管理多个单页应用","3-17通过Node.jsAPI启动Webpack","3-20加载SVG"],"html":"<div style='text-align: center'><a href='http://union-click.jd.com/jdc?d=1AMcaz'><img src='http://ou8vcvyuy.bkt.clouddn.com/dive-into-webpack.png' width='306px' height='411px'><a/> <h2><a target='_blank' href='http://union-click.jd.com/jdc?d=1AMcaz'>购买本书纸质版</a></h2></div>"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"github-buttons":{"buttons":[{"user":"gwuhaolin","type":"follow","size":"small","width":"150"},{"user":"gwuhaolin","repo":"dive-into-webpack","type":"star","size":"small"}]},"ga":{"configuration":"auto","token":"UA-54964850-3"},"sharing":{"facebook":false,"twitter":false,"google":false,"weibo":true,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"吴浩麟","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"9787121331725","variables":{},"title":"深入浅出 Webpack","language":"zh-hans","gitbook":"*","description":"本书按照入门、配置、实战、优化、原理的路线层层深入，涵盖了 Webpack 的方方面面。对于小白，本书可以作为 Webpack 入门教程，对于老手，本书可以进一步加深你对 Webpack 的理解。"},"file":{"path":"3实战/3-14构建离线应用.md","mtime":"2017-11-10T05:34:54.543Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-08-23T09:47:20.169Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-ga/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-modal/index.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-adsense/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

